#include "File.h"
#include "enginedirs.h"

#include <sstream>
#include <fstream>

namespace Lame3d
{
	File::File(const char* fname)
	{
		// Set directories
		std::stringstream ss;
		ss << getUserDir();
		ss << DIRSEP << fname;
		ss >> userPath;
		ss.clear();
		ss << getSystemDir();
		ss << DIRSEP << fname;
		ss >> systemPath;
		
		Recheck();
	}
	
	File::~File()
	{
	}
	
	bool File::UserExists() const
	{
		return uExists;
	}
	
	bool File::SystemExists() const
	{
		return sExists;
	}
	
	bool File::Exists() const
	{
		return uExists | sExists;
	}
	
	const std::string& File::GetUserPath() const
	{
		return userPath;
	}
	
	const std::string& File::GetSystemPath() const
	{
		return systemPath;
	}
	
	const std::string& File::GetPath() const
	{
		return !sExists | uExists ? userPath : systemPath;
	} 
	
	void File::Recheck()
	{
		// Stream trickery for existance check.
		uExists = std::ifstream(userPath.c_str()) != NULL;
		sExists = std::ifstream(systemPath.c_str()) != NULL;
	}
}

// eof
